package org.szrcb.temu.SalesManage.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.szrcb.temu.SalesManage.Vo.ResultVO;
import org.szrcb.temu.SalesManage.pojo.MallInfo;
import org.szrcb.temu.SalesManage.pojo.UserInfo;
import org.szrcb.temu.SalesManage.service.MallInfoService;
import org.szrcb.temu.SalesManage.service.UserInfoService;
import org.szrcb.temu.SalesManage.utils.ResultVOUtil;

import java.util.List;

@RestController
public class MallInfoController {
    @Autowired
    private MallInfoService mallInfoService;

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/queryMallList")
    public ResultVO queryMallList(@RequestHeader("access_token") String accessToken) {
        String userId = userInfoService.queryUserId(accessToken);
        List<MallInfo> mallInfoList = mallInfoService.queryMallList(userId);
        return ResultVOUtil.success(mallInfoList);
    }

    @PostMapping("/queryUserMallList")
    public ResultVO queryUserMallList(@RequestHeader("access_token") String accessToken) {
        String userId = userInfoService.queryUserId(accessToken);
        List<MallInfo> mallInfoList = mallInfoService.queryUserMallList(userId);

        return ResultVOUtil.success(mallInfoList);
    }

    @PostMapping("/updateVipState")
    public ResultVO updateVipState(@RequestHeader("access_token") String accessToken, UserInfo userInfo) {
        System.out.println(userInfo.getMallIdList().size());
//        JSONArray objects = JSON.parseArray(mallIdList);
//        JSONObject jsonObject = JSON.parseObject(mallIdList);
//        List<String> mallIds = jsonObject.getObject(mallIdList, List.class);
//        System.out.println(mallIdList.toString());
        mallInfoService.updateVipState(userInfo.getMallIdList());
        return ResultVOUtil.success("充值店铺会员成功");
    }

}
